package com.daos;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.model.Employee;

@Repository
public class EmployeeDao extends AbstractDao<Employee>{

	public Employee getEmployeeById(int id) {
		return(Employee) hibernateTemplate.find("from Employees e where e.id =?",id).get(0) ; 
	}

	public Employee getEmployeeByFirstAndLastName(String firstname,String lastname) {
		Employee employee =  (Employee) hibernateTemplate.find("from Employees e where e.firstname = ? " +
				"and e.lastname =  ?",firstname,lastname).get(0); 
		
		return employee != null ? employee : null;
	}

	@SuppressWarnings("unchecked")
	public List<Employee> getEmployees() {
		return hibernateTemplate.find("from Employees e order by e.firstname");  
	}
	
	public Employee getEmployeeByUsername(String username) {
		return(Employee) hibernateTemplate.find("from Employees e where e.username =?",username).get(0) ; 
	}
	
	public String getPasswordForEmployee(int id) {
		return(String) hibernateTemplate.find("select e.password from Employees e where e.id =?", id).get(0) ; 
	}

	public String getImageForEmployee(int id) {
		return(String) hibernateTemplate.find("select e.image from Employees e where e.id =?", id).get(0) ; 
	}

}
